package com.txx.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.txx.mapper.GoodsCategoryMapper;
import com.txx.mapper.GoodsCategoryParamMapper;
import com.txx.pojo.GoodsCategoryParam;
import com.txx.util.Constants;
import com.txx.vof.CategoryParamForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zgc
 * @Date: 2021/5/20 10:53
 */
@Service
public class GoodsCategoryParamServiceImpl implements GoodsCategoryParamService {

    @Autowired
    private GoodsCategoryParamMapper goodsCategoryParamMapper;

    @Override
    public int Insert(GoodsCategoryParam categoryParam) {
        categoryParam.setIsDelete(Constants.IsDelete.Off.ordinal());
        return goodsCategoryParamMapper.insert(categoryParam);
    }

    @Override
    public int Update(GoodsCategoryParam categoryParam) {
        return goodsCategoryParamMapper.updateById(categoryParam);
    }

    @Override
    public int Delete(Integer id) {
        return goodsCategoryParamMapper.deleteById(id);
    }

    @Override
    public List<GoodsCategoryParam> findParamByType(CategoryParamForm data) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if(data.getTypeId() != null)
        {
            queryWrapper.eq("type_id",data.getTypeId());
        }

        if(data.getCategoryId() != null)
        {
            queryWrapper.eq("category_id",data.getCategoryId());
        }
        return goodsCategoryParamMapper.selectList(queryWrapper);
    }
}
